import { createRouter,createWebHashHistory,RouteRecordRaw} from "vue-router";
import { userStore } from "../store/user.ts";

const routes:Array<RouteRecordRaw> = [
    {
        path:'/login',
        component:()=> import ('@/views/login/index.vue')
    },
    {
        path:'/login/serviceAgree',
        component:()=> import ('@/views/login/serviceAgree.vue')
    },
    {
        path:'/login/privacyPolicy',
        component:()=> import ('@/views/login/privacyPolicy.vue')
    },
    {
        path:'/task',
        component:()=> import ('@/views/task/index.vue')
    },
    {
        path:'/task/companySource',
        component:()=> import ('@/views/task/companySource.vue')
    },
    {
        path:'/task/details',
        component:()=> import ('@/views/task/details.vue')
    },
    {
        path:'/task/search',
        component:()=> import ('@/views/task/search.vue')
    },
    {
        path:'/contract',
        component:()=> import ('@/views/contract/index.vue')
    },
    {
        path:'/message',
        component:()=> import ('@/views/message/index.vue')
    },
    {
        path:'/message/systemList',
        component:()=> import ('@/views/message/systemList.vue')
    },
    {
        path:'/message/systemDetails/:id',
        component:()=> import ('@/views/message/syStemDetails.vue')
    },
    {
        path:'/message/talk/:id',
        component:()=> import ('@/views/message/talk.vue')
    },
    {
        path:'/talent',
        component:()=> import ('@/views/talent/index.vue')
    },
]
const router = createRouter({
    history:createWebHashHistory(),
    routes
})
// 路由守卫
router.beforeEach((to,from,next)=>{
    const store = userStore()
    // 验证token存在，则进入页面
    if(store.token){
        next()
    }else{
        if(to.path === '/login' || to.path === '/login/privacyPolicy' || to.path=== '/login/serviceAgree'){
            next()
        }else{
            next('/login')
        }
    }
})
export default  router
